<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>reduce方法的使用</title>
</head>

<body>
    <script>
        const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        // arr.reduce（function（上一次值，当前值）{}，初始值）
        const total = arr.reduce((prev, current) => prev + current, 0)
        console.log(total); // 45

        const employee = [
            {
                name: '张三',
                salary: 10000
            },
            {
                name: '李四',
                salary: 20000
            },
            {
                name: '王二',
                salary: 10000
            }
        ]

        // 对数组对象中的数据累加,薪资加 30%
        const totalSalary = employee.reduce((prev, current) => prev + current.salary * 1.3, 0)
        console.log(totalSalary); // 52000
    </script>
</body>

</html>